package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.XImageLoader;

import java.util.List;


/**
 * Created by itboye on 2017/3/17.
 */

public class GridViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> imageUrls;
    private int lastPosition = -1;//定义一个标记为最后选择的位置

    public GridViewAdapter(Context context, List<String> imageUrls, int lastPosition) {
        mContext = context;
        this.imageUrls = imageUrls;
        this.lastPosition=lastPosition;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Integer getItem(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return imageUrls == null ? 0 : imageUrls.size();
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rootView = LayoutInflater.from(mContext).inflate(R.layout.item_head_gridbiew,
                parent, false);
        ImageView imageView = (ImageView) rootView.findViewById(R.id.imgheadPres);
        ImageView imageViews = (ImageView) rootView.findViewById(R.id.imageView);
        if ( lastPosition== position) {//最后选择的位置
            imageViews.setVisibility(View.VISIBLE);
        } else {
            imageViews.setVisibility(View.GONE);
        }

        if (imageUrls != null) {
            XImageLoader.load(
                    Const.IMAGE_HEAD + imageUrls.get(position),
                    imageView);
        }

        return rootView;
    }


}
